<!DOCTYPE html>
<html lang="zh" style="height: 100%" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<body style="background: white;height: 100%" class="list">
<div th:replace="include/head.html::html"></div>
<div class="pear-container">
    <div class="layui-card">
        <!--查询from 表单-->
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form" >
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">标题</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>

                            <label class="layui-form-label">方法</label>
                            <div class="layui-input-inline">
                                <input type="text" name="method" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>

                            <label class="layui-form-label">操作人</label>
                            <div class="layui-input-inline">
                                <input type="text" name="operName" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">操作url</label>
                            <div class="layui-input-inline">
                                <input type="text" name="operUrl" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>

                            <label class="layui-form-label">操作ip</label>
                            <div class="layui-input-inline">
                                <input type="text" name="operIp" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <!--<button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>-->
                            <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="search">
                                <i class="layui-icon layui-icon-search"></i>
                                查询
                            </button>
                        </div>

                    </div>
                </form>
            </div>

        </div>
        <!--表格中的数据 并不显示-->
        <div class="layui-card-body">
            <!--数据表格 -->
            <table id="table" lay-filter="table"></table>
            <!--表格每行的 的操作按钮 -->
            <script type="text/html" id="toolbar">
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"
                 shiro:hasPermission="log:del"><i
                        class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>


</div>
<script type="text/javascript" th:inline="none">
    var table ;
    layui.use(['table', 'laydate'], function () {
        var $ = layui.$;
        table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        table.render({
            elem: '#table'
            , id: 'table'
            , loading: true
            , method: 'post'
            , url: 'log/page' //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {type: 'numbers', fixed: 'left', title: '序号'}
                , {field: 'title', title: '标题'}
                , {field: 'method', title: '方法'}
                , {field: 'operName', title: '操作人'}
                , {field: 'operUrl', title: '操作url'}
                , {field: 'operIp', title: '操作ip'}
                // , {field: 'operLocation', title: '操作地址'}
                , {field: 'operParam', title: '操作参数'}
                , {field: 'errorMsg', title: '错误信息'}
                , {field: 'operTime', title: '请求时间'}
                // , {fixed: 'right',title:'操作', width: 165, align: 'center', toolbar: '#toolbar'}
            ]]
        });
        //监听搜索
        form.on('submit(search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('table', {where: field});
        });
        //监听行工具事件
        //注：tool 是工具条事件名，table 是 table 原始容器的属性 lay-filter="对应的值"
        table.on('tool(table)', function (obj) {
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.post("log/del",{operId:data.operId},function (res) {
                        //向服务端发送删除指令
                        if(res.code === 0){
                            layer.msg(res.msg);
                            layer.close(index);
                            table.reload('table');
                        }else {
                            layer.msg(res.msg);
                        }
                    });
                });
            }
        });
    });
</script>
</body>
</html>
